package cn.acewill.yxd.yunxundian.componet;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.widget.ImageView;

import cn.acewill.yxd.yunxundian.R;

/**
 * Created by xxx on 2018/1/29.
 */

public class StarImageView extends android.support.v7.widget.AppCompatImageView{
    private Paint redPaint;
    private Paint bPaint;
    public StarImageView(Context context) {
        super(context);
        initPaint();
    }

    public StarImageView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initPaint();
    }

    public StarImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initPaint();
    }

    public void initPaint(){
        redPaint = new Paint();
        redPaint.setColor(getResources().getColor(R.color.red_triangle));
        redPaint.setStyle(Paint.Style.FILL);
        bPaint = new Paint();
        bPaint.setColor(getResources().getColor(R.color.white));
        bPaint.setStyle(Paint.Style.FILL);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Drawable drawable = getDrawable();
        Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
        Path path = new Path();
            path.moveTo(0,0);
            path.lineTo(0,120);
            path.lineTo(120,0);
            path.close();
            canvas.drawPath(path,redPaint);
            canvas.drawBitmap(bitmap,0,0,bPaint);
        }
}
